package net.zigin.nhi.could.waste.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import net.zigin.commons.util.ReflectUtil;
import net.zigin.nhi.could.waste.annotation.EpiResponseFilter;
import net.zigin.nhi.could.waste.annotation.EpiResponseFilters;
import net.zigin.nhi.could.waste.annotation.LoginWhitePathAnnotation;
import net.zigin.nhi.could.waste.model.AreaProvince;
import net.zigin.nhi.could.waste.service.AreaCityService;
import net.zigin.nhi.could.waste.service.AreaProvinceService;

import net.zigin.nhi.could.waste.service.AreaRegionService;
import net.zigin.nhi.could.waste.service.AreaTownService;
import net.zigin.nhi.could.waste.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * AreaProvince控制器类
 *
 * @author mgw1986
 * @version V1.0
 * @ClassName: AreaProvinceController
 * @date 2021-9-9 21:00:32
 */
@Api(tags = "地区列表")
@RestController
@RequestMapping("/area")
public class AreaProvinceController extends BaseController {
    @Autowired
    private AreaProvinceService areaProvinceService;
    @Autowired
    private AreaCityService areaCityService;
    @Autowired
    private AreaRegionService areaRegionService;
    @Autowired
    private AreaTownService areaTownService;

    @LoginWhitePathAnnotation
    @ApiOperation("省列表")
    @GetMapping("/getAll")
    @EpiResponseFilters({
            @EpiResponseFilter(exclude = "createTime,createUser,id,isDelete,latitude,longitude,modifyTime,modifyUser", target = AreaTownVo.class)
    })
    public JsonForResult<List<AreaTownVo>> getAllList(){
        List<AreaTownVo> all = areaProvinceService.getAll();
        return JsonForResult.<List<AreaTownVo>>builder().data(all).success(true).build();
    }

    /**
     * 省列表
     * @return 省列表
     */
    @LoginWhitePathAnnotation
    @ApiOperation("省列表")
    @GetMapping("/getProvinceList")
    @EpiResponseFilters({
            @EpiResponseFilter(exclude = "createTime,createUser,id,isDelete,latitude,longitude,modifyTime,modifyUser", target = AreaProvinceVo.class)
    })
    public JsonForResult<List<AreaProvinceVo>> getList() {
        List<AreaProvince> areaProvinces = areaProvinceService.selectAllList();
        List<AreaProvinceVo> areaProvinceVos = ReflectUtil.copyProperties(areaProvinces, AreaProvinceVo.class);
        return JsonForResult.<List<AreaProvinceVo>>builder().data(areaProvinceVos).success(true).build();
    }

    /**
     * 城市列表
     * @param provinceCode 省编码
     * @return 城市列表
     */
    @LoginWhitePathAnnotation
    @ApiOperation("城市列表")
    @ApiImplicitParam(name = "provinceCode", value = "省编码", required = true, dataType = "String")
    @EpiResponseFilters({
            @EpiResponseFilter(exclude = "createTime,createUser,id,isDelete,latitude,longitude,modifyTime,modifyUser", target = AreaCityVo.class)
    })
    @GetMapping("/getCityList")
    public JsonForResult<List<AreaCityVo>> getCityList(String provinceCode) {
        List<AreaCityVo> areaCityVos = areaCityService.getListByProvinceCode(provinceCode);
        return JsonForResult.<List<AreaCityVo>>builder().data(areaCityVos).success(true).build();
    }

    /**
     * 区域列表
     * @param cityCode 城市编码
     * @return 区域列表
     */
    @LoginWhitePathAnnotation
    @ApiOperation("区列表")
    @ApiImplicitParam(name = "cityCode", value = "市编码", required = true, dataType = "String")
    @EpiResponseFilters({
            @EpiResponseFilter(exclude = "createTime,createUser,id,isDelete,latitude,longitude,modifyTime,modifyUser", target = AreaRegionVo.class)
    })
    @GetMapping("/getRegionList")
    public JsonForResult<List<AreaRegionVo>> getRegionList(String cityCode) {
        List<AreaRegionVo> areaRegionVos = areaRegionService.getListByCityCode(cityCode);
        return JsonForResult.<List<AreaRegionVo>>builder().data(areaRegionVos).success(true).build();
    }

    /**
     * 镇列表
     * @param regionCode 区域编码
     * @return 镇列表
     */
    @LoginWhitePathAnnotation
    @ApiOperation("镇列表")
    @ApiImplicitParam(name = "regionCode", value = "区编码", required = true, dataType = "String")
    @EpiResponseFilters({
            @EpiResponseFilter(exclude = "createTime,createUser,id,isDelete,latitude,longitude,modifyTime,modifyUser", target = AreaTownVo.class)
    })
    @GetMapping("/getTownList")
    public JsonForResult<List<AreaTownVo>> getTownList(String regionCode) {
        List<AreaTownVo> areaTownVos = areaTownService.getListByRegionCode(regionCode);
        return JsonForResult.<List<AreaTownVo>>builder().data(areaTownVos).success(true).build();
    }

}
